package eval.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import org.jfree.data.xy.XYIntervalSeries;

import se.diod.swing.JxPanel;
import eval.results.IResultsData;

public class ResultsFrame extends JFrame {

	private static final long serialVersionUID = 1L;

	private List<IResultsData> resultsList;

	private GridBagConstraints cJx;
	private GridBagConstraints c;
	private JPanel panel;
	private String resFileName;

	public ResultsFrame(List<IResultsData> resultsData, String resFileName) {
		super("Placements results");
		this.resultsList = resultsData;
		this.resFileName = resFileName;
		init();
	}

	private void init() {
		this.panel = new JPanel();
		panel.setLayout(new GridBagLayout());

		this.cJx = new GridBagConstraints();
		cJx.fill = GridBagConstraints.BOTH;
		cJx.weightx = 1.0;
		cJx.weighty = 1.0;
		cJx.gridx = 0;
		cJx.gridy = 0;

		this.c = new GridBagConstraints();
		c.weightx = 1.0;
		c.weighty = 1.0;
		c.gridx = 0;
		c.gridy = 0;

//		createPlotPanel("Experiment data (cumulative measures)",
//				createExperimentDataPanel());
		
		createPlotPanel("VM Rejected", createRejected("vmRejected") );
		createPlotPanel("VM Relocated ", createVmRelocated("vmRelocated") );
		createPlotPanel("Total Cpu Free At Cloud ", createTotalCpuFreeAtCloud("CpuFree"));
		createPlotPanel("Sum of Min of VM/ Total capcity", createMinOnTotalDemand("minOnCap"));
		createPlotPanel("Open Host", createNumberOfOpenHost("openHost"));
		createPlotPanel("Total Demand ", createTotalDemand("demand") );
		createPlotPanel("Satisfied  Demand (CPU) ", createSatisfiedDemand("satisfiedDemand"));
		createPlotPanel("Un-Satisfied Demand (CPU)", createUnSatisfiedDemand("unSatisfiedDemand"));
		createPlotPanel("Energy (Cost)", createTotalConsumption("energy"));

		add(new JScrollPane(panel));

		setPreferredSize(new Dimension(800, 800));

		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

	private Component createTotalDemand(String chartLabel) {
		String tag;
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
 		for(int i=0; i<resultsList.size();i++) {
			IResultsData results = resultsList.get(i);
			tag = results.getEngineType();
			final XYIntervalSeries totalDemandSeries = new XYIntervalSeries(tag);
			int[] totalDemand = results.getTotalCpuDemandAtCloud();
			for (int j = 0; j < results.getExperimentTicks(); j++) {
				int v = totalDemand[j];
				totalDemandSeries.add(j, j, j, v, v, v);
			}
			seriesList.add(totalDemandSeries);
 		}
		Component plot = new PlotPanel("Tick", "GHz", true, seriesList, 0,chartLabel,resFileName);
		return plot;
	}
	
	private Component createMinOnTotalDemand(String chartLabel) {
		String tag;
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
 		for(int i=0; i<resultsList.size();i++) {
			IResultsData results = resultsList.get(i);
			tag = results.getEngineType();
			final XYIntervalSeries minOnTotalDemandSeries = new XYIntervalSeries(tag);
			double[] minOnTotalDemand = results.getSumOfMinREservtion();
			for (int j = 0; j < results.getExperimentTicks(); j++) {
				double v = minOnTotalDemand[j];
				minOnTotalDemandSeries.add(j, j, j, v, v, v);
			}
			seriesList.add(minOnTotalDemandSeries);
 		}
		Component plot = new PlotPanel("Tick", "GHz", true, seriesList, 0,chartLabel,resFileName);
		return plot;
	}
	
	private Component createNumberOfOpenHost(String chartLabel) {
		String tag;
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
 		for(int i=0; i<resultsList.size();i++) {
			IResultsData results = resultsList.get(i);
			tag = results.getEngineType();
			final XYIntervalSeries incomeForDemandSeries = new XYIntervalSeries(tag);
			int[] incomeforDemand = results.getNumberOfOpenHostAtCloud();
			for (int j = 0; j < results.getExperimentTicks(); j++) {
				int v = incomeforDemand[j];
				incomeForDemandSeries.add(j, j, j, v, v, v);
			}
			seriesList.add(incomeForDemandSeries);
 		}
		Component plot = new PlotPanel("Tick", "Hosts", true, seriesList, 0,chartLabel,resFileName);
		return plot;
	}
	
	
	private Component createSatisfiedDemand(String chartLabel) {
		String tag;
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
 		for(int i=0; i<resultsList.size();i++) {
			IResultsData results = resultsList.get(i);
			tag = results.getEngineType();
			final XYIntervalSeries satisfiedDemandSeries = new XYIntervalSeries(tag);
			int[] SatisfiedDemand = results.getTotalDemandSatisfiedAtCloud();
			for (int j = 0; j < results.getExperimentTicks(); j++) {
				int v = SatisfiedDemand[j];
				satisfiedDemandSeries.add(j, j, j, v, v, v);
			}
			seriesList.add(satisfiedDemandSeries);
 		}
		Component plot = new PlotPanel("Tick", "GHz", true, seriesList, 0,chartLabel,resFileName);
		return plot;
	}
	
	private Component createUnSatisfiedDemand(String chartLabel) {
		String tag;
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
 		for(int i=0; i<resultsList.size();i++) {
			IResultsData results = resultsList.get(i);
			tag = results.getEngineType();
			final XYIntervalSeries unSatisfiedDemandSeries = new XYIntervalSeries(tag);
			int[] unSatisfiedDemand = results.getTotalDemandUnSatisfiedAtCloud();
			for (int j = 0; j < results.getExperimentTicks(); j++) {
				int v = unSatisfiedDemand[j];
				unSatisfiedDemandSeries.add(j, j, j, v, v, v);
			}
			seriesList.add(unSatisfiedDemandSeries);
 		}
		Component plot = new PlotPanel("Tick", "GHz", true, seriesList, 0,chartLabel,resFileName);
		return plot;
	}
	
	private Component createTotalConsumption(String chartLabel) {
		String tag;
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
 		for(int i=0; i<resultsList.size();i++) {
			IResultsData results = resultsList.get(i);
			tag = results.getEngineType();
			final XYIntervalSeries totalConsumptionSeries = new XYIntervalSeries(tag);
			double[] totalConsumption = results.getTotalConsumption();
			for (int j = 0; j < results.getExperimentTicks(); j++) {
				double v = totalConsumption[j];
				totalConsumptionSeries.add(j, j, j, v, v, v);
			}
			seriesList.add(totalConsumptionSeries);
 		}
		Component plot = new PlotPanel("Tick", "Electricity", true, seriesList, 0,chartLabel,resFileName);
		return plot;
	}
	
	private Component createRejected(String chartLabel) {
		String tag;
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
 		for(int i=0; i<resultsList.size();i++) {
			IResultsData results = resultsList.get(i);
			tag = results.getEngineType();
			final XYIntervalSeries rejectedSeries = new XYIntervalSeries(tag);
			int[] rejected = results.getNumberOfVmsReject();
			for (int j = 0; j < results.getExperimentTicks(); j++) {
				int v = rejected[j];
				rejectedSeries.add(j, j, j, v, v, v);
			}
			seriesList.add(rejectedSeries);
 		}
		Component plot = new PlotPanel("Tick", "VM's", true, seriesList, 0,chartLabel,resFileName);
		return plot;
	}
	
	private Component createVmRelocated(String chartLabel) {
		String tag;
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
 		for(int i=0; i<resultsList.size();i++) {
			IResultsData results = resultsList.get(i);
			tag = results.getEngineType();
			final XYIntervalSeries vmRelocatedSeries = new XYIntervalSeries(tag);
			int[] vmRelocated = results.getvmRelocate();
			for (int j = 0; j < results.getExperimentTicks(); j++) {
				int v = vmRelocated[j];
				vmRelocatedSeries.add(j, j, j, v, v, v);
			}
			seriesList.add(vmRelocatedSeries);
 		}
		Component plot = new PlotPanel("Tick", "VM's", true, seriesList, 0,chartLabel,resFileName);
		return plot;
	}
	
	private Component createTotalCpuFreeAtCloud(String chartLabel) {
		String tag;
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
 		for(int i=0; i<resultsList.size();i++) {
			IResultsData results = resultsList.get(i);
			tag = results.getEngineType();
			final XYIntervalSeries totalCpuFreeAtCloudSeries = new XYIntervalSeries(tag);
			int[] totalCpuFreeAtCloud = results.getTotalCpuFreeAtCloud();
			for (int j = 0; j < results.getExperimentTicks(); j++) {
				int v = totalCpuFreeAtCloud[j];
				totalCpuFreeAtCloudSeries.add(j, j, j, v, v, v);
			}
			seriesList.add(totalCpuFreeAtCloudSeries);
 		}
		Component plot = new PlotPanel("Tick", "GHz", true, seriesList, 0,chartLabel,resFileName);
		return plot;
	}
	
//	private Component createNewCom() {
//		String tag;
//		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
// 		for(int i=0; i<resultsList.size();i++) {
//			IResultsData results = resultsList.get(i);
//			tag = results.getEngineType();
//			final XYIntervalSeries totalDemandSeries = new XYIntervalSeries(tag);
//			int[] totalDemand = results.
//			for (int j = 0; j < results.getExperimentTicks(); j++) {
//				double v = totalDemand[j];
//				totalDemandSeries.add(j, j, j, v, v, v);
//			}
//			seriesList.add(totalDemandSeries);
// 		}
//		Component plot = new PlotPanel("Tick", "Score", true, seriesList, 0);
//		return plot;
//	}
	
	private JLabel createNewLabelWithString(String msg) {
		return new JLabel(msg);
	}

	private void createPlotPanel(String title, Component component) {
		JxPanel plotPanel = createJxPanel(title);
		plotPanel.setLayout(new GridBagLayout());
		plotPanel.add(component, cJx);
		panel.add(plotPanel, c);
		// increment grid row
		c.gridy++;
	}

	public void display() {
		pack();
		setLocationRelativeTo(null);
		setVisible(true);
	}

	private final static GradientPaint JX_PANEL_GRADIENT = new GradientPaint(0,
			0, new Color(255, 168, 21), 500, 0, Color.white);
	private final static Color JX_PANEL_FONT_COLOR = new Color(200, 1, 1);

	private static JxPanel createJxPanel(String title) {
		JxPanel jxPanel = new JxPanel(title);
		jxPanel.setCollapsable(true);
		jxPanel.setGradient(JX_PANEL_GRADIENT);
		jxPanel.setFontColor(JX_PANEL_FONT_COLOR);
		return jxPanel;
	}
	
/*
	private Component createBaseEnergyConsumption() {
		final XYIntervalSeries maxHostLoadSeries = new XYIntervalSeries(
				"Max host load");

		final XYIntervalSeries avgHostLoadSeries = new XYIntervalSeries(
				"Avg host load");

		final XYIntervalSeries minHostLoadSeries = new XYIntervalSeries(
				"Min host load");

		double maxLoadOnHost[] = results.getMaxLoadOnHost();
		double avgLoadOnHost[] = results.getAvgLoadOnHost();
		double minLoadOnHost[] = results.getMinLoadOnHost();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			double v = maxLoadOnHost[i];
			maxHostLoadSeries.add(i, i, i, v, v, v);
			v = avgLoadOnHost[i];
			avgHostLoadSeries.add(i, i, i, v, v, v);
			v = minLoadOnHost[i];
			minHostLoadSeries.add(i, i, i, v, v, v);
		}
		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		seriesList.add(maxHostLoadSeries);
		seriesList.add(avgHostLoadSeries);
		seriesList.add(minHostLoadSeries);

		Component plot = new PlotPanel("Tick", "Max load on host", true,
				seriesList, 0);

		return plot;
	}
*//*
	private Component createHostsPanel() {
		final XYIntervalSeries activeHostsSeries = new XYIntervalSeries(
				"Active hosts");
		int activeHosts[] = results.getNumberOfActiveHosts();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			int v = activeHosts[i];
			activeHostsSeries.add(i, i, i, v, v, v);
		}

		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		seriesList.add(activeHostsSeries);

		Component plot = new PlotPanel("Tick", "Active hosts", true,
				seriesList, 0);
		return plot;
	}
*//*
	private Component createPlacementDelayed() {
		final XYIntervalSeries placementDelayedSeries = new XYIntervalSeries(
				"Placement delayed");
		final XYIntervalSeries ongoingPlacementSeries = new XYIntervalSeries(
				"Ongoing placement computed");

		final XYIntervalSeries startedPlacementSeries = new XYIntervalSeries(
				"Started placement computation");

		boolean[] placementDelayed = results.getPlacementDelayed();
		boolean[] ongoingPlacement = results.getOngoingOptimizationComputed();
		int[] startedPlacement = results.getStartedComputingPlacement();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			if (placementDelayed[i])
				placementDelayedSeries.add(i, i, i, 1, 1, 1);
			else
				placementDelayedSeries.add(i, i, i, 0, 0, 0);

			if (ongoingPlacement[i])
				ongoingPlacementSeries.add(i, i, i, 1, 1, 1);
			else
				ongoingPlacementSeries.add(i, i, i, 0, 0, 0);

			int v = startedPlacement[i];
			startedPlacementSeries.add(i, i, i, v, v, v);
		}

		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		seriesList.add(placementDelayedSeries);
		seriesList.add(ongoingPlacementSeries);
		seriesList.add(startedPlacementSeries);

		Component plot = new PlotPanel("Tick", "Placement computation", true,
				seriesList, 0);

		return plot;
	}
*//*
	private Component createDemandSamplePlanel() {
		final XYIntervalSeries demandSampleSeries = new XYIntervalSeries(
				"CPU Demand");
		final XYIntervalSeries rawDemandSampleSeries = new XYIntervalSeries(
				"Non-smoothed demand");

		double[] demandSample = results.getSmoothedDemand();
		int[] rawDemandSample = results.getRawDemand();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			double v = demandSample[i];
			demandSampleSeries.add(i, i, i, v, v, v);
			v = rawDemandSample[i];
			rawDemandSampleSeries.add(i, i, i, v, v, v);
		}

		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		seriesList.add(demandSampleSeries);
		seriesList.add(rawDemandSampleSeries);

		Component plot = new PlotPanel("Tick", "CPU demand", true, seriesList,
				0);

		return plot;
	}
*//*
	private Component createSatisfiedDemandPanel() {
		final XYIntervalSeries satisfiedDemandSeries = new XYIntervalSeries(
				"Percentage of total satisfied demand");

		final XYIntervalSeries vmsWithSatisfiedDemandSeries = new XYIntervalSeries(
				"Percentage of VMs with satisfied demand");

		double[] satisfiedDemand = results.getSatisfiedDemand();
		double[] vmsWithSatisfiedDemand = results
				.getVMsWithSatisfiedDemandPerc();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			double v = satisfiedDemand[i];
			satisfiedDemandSeries.add(i, i, i, v, v, v);
			v = vmsWithSatisfiedDemand[i];
			vmsWithSatisfiedDemandSeries.add(i, i, i, v, v, v);
		}

		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		seriesList.add(satisfiedDemandSeries);
		seriesList.add(vmsWithSatisfiedDemandSeries);

		Component plot = new PlotPanel("Tick", "Satisfied demand (%)", true,
				seriesList, 0);

		return plot;
	}
*//*
	private Component createTotalLoadPanel() {
		final XYIntervalSeries totalCPULoadSeries = new XYIntervalSeries(
				"Total CPU load (allocated)");

		final XYIntervalSeries totalMemLoadSeries = new XYIntervalSeries(
				"Total mem load");

		final XYIntervalSeries totalCPUReservationLoadSeries = new XYIntervalSeries(
				"Total CPU load (reservation)");

		double totalCpuLoad[] = results.getTotalCpuLoad();
		double totalMemLoad[] = results.getTotalMemLoad();

		double totalReservationLoad[] = results.getTotalReservationLoad();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			double v = totalCpuLoad[i];
			totalCPULoadSeries.add(i, i, i, v, v, v);

			v = totalMemLoad[i];
			totalMemLoadSeries.add(i, i, i, v, v, v);

			v = totalReservationLoad[i];
			totalCPUReservationLoadSeries.add(i, i, i, v, v, v);
		}

		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		seriesList.add(totalCPULoadSeries);
		seriesList.add(totalMemLoadSeries);
		seriesList.add(totalCPUReservationLoadSeries);

		Component plot = new PlotPanel("Tick", "Load (%)", true, seriesList, 0);

		return plot;
	}
*//*
	private Component createDeploySetsPanel() {

		// XYIntervalSeries seriesForDeploySet[] = new
		// XYIntervalSeries[VMConfigurationEnum
		// .values().length];

		XYIntervalSeries totalVMRequestSeries = new XYIntervalSeries(
				"Total number of requested VMs for deploy");

		// int j = 0;
		// for (VMConfigurationEnum configuration :
		// VMConfigurationEnum.values()) {
		// seriesForDeploySet[j] = new XYIntervalSeries("VM "
		// + configuration.name());
		// j++;
		// }

		DeploySet receivedDeploySets[] = results.getReceivedDeploySets();
		int sizeOfReceivedDeploySets[] = results.getSizeOfReceivedDeploySets();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			// int s = 0;
			// for (VMConfigurationEnum configuration : VMConfigurationEnum
			// .values()) {

			// long v = deploySets[i].getNumberOfVmOfType(configuration);
			long v = sizeOfReceivedDeploySets[i];
			totalVMRequestSeries.add(i, i, i, v, v, v);
			// s++;
			// }
		}

		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		//
		// for (XYIntervalSeries series : seriesForDeploySet) {
		// seriesList.add(series);
		// }

		seriesList.add(totalVMRequestSeries);

		Component plot = new PlotPanel("Tick", "Received deploy setss", true,
				seriesList, 0);

		return plot;
	}
*//*
	private Component createNumberOfRelocationsPanel() {
		final XYIntervalSeries placedVMTimeSeries = new XYIntervalSeries(
				"Number of relocations");

		int numberOfChanges[] = results.getNumberOfRelocations();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			long v = numberOfChanges[i];
			placedVMTimeSeries.add(i, i, i, v, v, v);
		}

		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		seriesList.add(placedVMTimeSeries);

		Component plot = new PlotPanel("Tick", "Relocations", true, seriesList,
				0);

		return plot;
	}
*//*
	private Component createPlacedVMsPanel() {
		final XYIntervalSeries placedVMTimeSeries = new XYIntervalSeries(
				"Placed VMs");
		final XYIntervalSeries vmWithSatisfiedDemandSeries = new XYIntervalSeries(
				"Number of VM with satisfied demand");

		int[] placedVMs = results.getNumberOfPlacedVMs();
		int[] vmWithSatisfiedDemand = results.getVMsWithSatisfiedDemand();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			int v = placedVMs[i];
			placedVMTimeSeries.add(i, i, i, v, v, v);
			v = vmWithSatisfiedDemand[i];
			vmWithSatisfiedDemandSeries.add(i, i, i, v, v, v);
		}

		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		seriesList.add(placedVMTimeSeries);
		seriesList.add(vmWithSatisfiedDemandSeries);
		Component plot = new PlotPanel("Tick", "VMs", true, seriesList, 0);

		return plot;
	}
*//*
	private Component createExecutionTimePanel() {

		final XYIntervalSeries executionTimeSeries = new XYIntervalSeries(
				"Engine execution time");

		final XYIntervalSeries tickComputationTimeSeris = new XYIntervalSeries(
				"Tick execution time");

		double[] engineComputationTime = results.getComputationTime();
		double[] tickComputationTime = results.getTickComputationTime();

		for (int i = 0; i < results.getSimulationTicks(); i++) {
			double v = engineComputationTime[i];
			executionTimeSeries.add(i, i, i, v, v, v);
			v = tickComputationTime[i];
			tickComputationTimeSeris.add(i, i, i, v, v, v);
		}

		List<XYIntervalSeries> seriesList = new ArrayList<XYIntervalSeries>();
		seriesList.add(executionTimeSeries);
		seriesList.add(tickComputationTimeSeris);

		Component plot = new PlotPanel("Tick", "Time (sec)", true, seriesList,
				0);

		return plot;
	}
*//*
	private Component createExperimentDataPanel() {
		JPanel panel = new JPanel();
		DecimalFormat df = new DecimalFormat("##.###");

		String s = " ";
		for (int i = 0; i < 169; i++)
			s += " ";

		List<String> messages = new ArrayList<String>();
		messages.add(s);
		messages.add(" Optimization goal: " + results.getEngineType());
		messages.add(" Execution time: "
				+ results.getTotalExperimentExecutionTimeInSec() + " sec");
		messages.add(" Execution time (ongoing): "
				+ df.format(results.getAverageOngoingExecutionTimeInSec())
				+ " sec");
		messages.add(" Average satisfied demand per tick: "
				+ df.format(results.averageSatisfiedDemandPerTick()) + "%");
		messages.add(" Average percentage of VMs satisfied per tick: "
				+ df.format(results.averageSatisfiedVMPerTickPerc()) + "%");
		messages.add(" Average load of data center "
				+ df.format(results.getAverageTotalLoad()) + "%");
		messages.add(" Average number of relocations per optimization tick: "
				+ df.format(results.averageNumberOfRelocationsPerOptimization()));
		messages.add(" Average number of active hosts: "
				+ df.format(results.getAverageNumberOfHosts()));
		messages.add(" Average max load "
				+ df.format(results.getAverageMaxLoad()));
		messages.add(" Average load balancing score on allocation: "
				+ df.format(results.getAverageLoadBalancingOnAllocation()));
		messages.add(" Average load balancing score on demand: "
				+ df.format(results.getAverageLoadBalancingOnDemand()));
		messages.add(" Average load balancing score on reservation: "
				+ df.format(results.getAverageLoadBalancingOnReservation()));
		messages.add("");

		int cols = 1;

		panel.setLayout(new GridLayout(messages.size() + 1, cols, 10, 2));

		for (String message : messages) {
			panel.add(createNewLabelWithString(message));
		}

		panel.add(new JLabel());

		// PlotIOSerializer.writePanelInFile(messages);

		return panel;
	}
*/
	

	// public void saveComponentAsJPEG(Component myComponent, String filename) {
	// Dimension size = myComponent.getSize();
	// BufferedImage myImage =
	// new BufferedImage(size.width, size.height,
	// BufferedImage.TYPE_INT_RGB);
	// Graphics2D g2 = myImage.createGraphics();
	// myComponent.paint(g2);
	// try {
	// OutputStream out = new FileOutputStream(filename);
	// JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
	// encoder.encode(myImage);
	// out.close();
	// } catch (Exception e) {
	// System.out.println(e);
	// }
	// }

}
